<template>
	<view class="card">
		<view class="header">
			<view class="cardTitle">
				<text>{{title}}</text>
			</view>
			<view class="moreBtn" @click="toRank">
				<text>更多</text>
				<image src="/static/images/gengduo.png" mode="widthFix"></image>
			</view>
		</view>

		<swiper class="swiper" duration="500" previous-margin="40rpx" next-margin="60rpx">
			<swiper-item v-for="(item,index) in list" :key="index">
				<view class="swiper-item">
					<view class="itemTitle" @click="topTopListDetail(item)">
						<text>{{item.name}}</text>
						<image src="/static/images/gengduo.png" mode="widthFix"></image>
					</view>
					<view class="songItem" v-for="(item2,index2) in songListDetail[index]" :key="index2" @click="playMusic(item2.id)">
						<image v-show="item2.al.picUrl" :src="item2.al.picUrl" mode="widthFix"></image>
						<view class="songInfo">
							<text>{{ index2 + 1 }}</text>
							<text>{{ item2.name }}</text>
							<text> - {{ item2.ar[0].name }}</text>
						</view>
					</view>
				</view>
			</swiper-item>
		</swiper>
	</view>
</template>

<script>
	import { mapMutations } from 'vuex'
	import {
		getSongListDetail,
		getMusicCover
	} from '@/api/music.js'
	export default {
		props: {
			title: {
				type: String,
				default: ''
			},
			list: {
				type: Array,
				default: []
			},
			itemTitleKey: {
				type: String,
				default: 'name'
			},
			itemImgKey: {
				type: String,
				default: 'picUrl'
			},
			itemPlayCountKey: {
				type: String,
				default: 'playCount'
			},
			showShadow: {
				type: Boolean,
				default: false
			}
		},
		data() {
			return {
				// 歌单详细
				songListDetail: [],
				icons: [
					'/static/images/top.png',
					'/static/images/sub.png',
					'/static/images/bottom.png',
				]
			}
		},
		watch: {
			list(e) {
				e.forEach(item => {
					getSongListDetail(item.id).then(res => {
						let a = res.data.playlist.tracks.slice(0, 3)
						this.songListDetail.push(a)
					})
				})
			}
		},
		methods: {
			...mapMutations(['changeCurrentMusicId']),
			// 播放歌曲
			playMusic(id) {
				this.changeCurrentMusicId(id)
			},
			// 跳转某一排行榜详情页面
			topTopListDetail(item) {
				console.log(item)
				uni.navigateTo({
					url: `/pages/music/songList/songListDetail?id=${item.id}`
				})
			},
			// 跳转所有排行榜页面
			toRank() {
				uni.navigateTo({
					url: '/pages/found/rank'
				})
			}
		}
	}
</script>

<style lang="less" scoped>
	.card {
		width: 750rpx;
		border-radius: 20rpx;
		background-color: #fff;
		padding: 0 0 30rpx;

		.header {
			display: flex;
			justify-content: space-between;
			align-items: center;
			width: 750rpx;
			height: 100rpx;
			padding: 0 30rpx;

			.cardTitle {
				font-size: 34rpx;
				letter-spacing: 3rpx;
				font-weight: 800;
			}

			.moreBtn {
				display: flex;
				justify-content: center;
				align-items: center;
				width: 130rpx;
				height: 50rpx;
				border-radius: 25rpx;
				border: 1rpx solid #ddd;

				image {
					width: 20rpx;
				}
			}
		}

		.swiper {
			height: 440rpx;
			.swiper-item {
				width: 630rpx;
				height: 420rpx;
				padding: 0 20rpx 20rpx 30rpx;
				border-radius: 18rpx;
				box-shadow: 2rpx 2rpx 8rpx 6rpx rgba(0, 0, 0, .08);
				margin: 10rpx 0 0 20rpx;
				&:first-child {
					margin-left: 10rpx;
				}


				.itemTitle {
					display: flex;
					justify-content: center;
					align-items: center;
					width: 100%;
					height: 100rpx;

					text {
						font-size: 34rpx;
						letter-spacing: 3rpx;
						font-weight: bolder;
					}

					image {
						width: 25rpx;
					}
				}

				.songItem {
					display: flex;
					// justify-content: center;
					align-items: center;
					width: 590rpx;
					height: 100rpx;
					.songInfo {
						width: 460rpx;
						height: 100rpx;
						line-height: 100rpx;
						text {
							&:first-child {
								font-size: 32rpx;
								font-weight: bolder;
								padding: 0 20rpx;
								color: #000;
							}
							&:nth-child(2) {
								font-size: 30rpx;
							}
							&:last-child {
								font-size: 24rpx;
								color: #666;
								margin-left: 4rpx;
							}
						}
					}
					image {
						width: 80rpx;
						border-radius: 12rpx;
					}
				}
			}
		}
	}
</style>
